//
//  JudgeMentInternet.m
//  XIWenLeJian
//
//  Created by lanou3g on 15/11/16.
//  Copyright © 2015年 蓝足. All rights reserved.
//

#import "JudgeMentInternet.h"
#import "AFNetworking.h"

static JudgeMentInternet *judgeMent;

@implementation JudgeMentInternet

+ (JudgeMentInternet *)defaultInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        judgeMent = [[JudgeMentInternet alloc]init];
    });
    return judgeMent;
}

- (void)changeInternet
{
    // 建立网络状态监控类, 单例
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    // 当网络发生变化的时候调用这个 block
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWiFi:
                self.isWifi = YES;
                self.status = @"WiFi";
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                self.isWifi = NO;
                self.status = @"data";
            }
                break;
            case AFNetworkReachabilityStatusNotReachable:{
                self.isWifi = NO;
                self.status = @"noInternet";
            }
                break;
            case AFNetworkReachabilityStatusUnknown:{
                self.isWifi = NO;
                self.status = @"unKnowInternet";
            }
                break;
                
            default:
                break;
        }
    }];
    // 开始监控
    [mgr startMonitoring];
}

// 如果控制器没了, 就不再监控
- (void)dealloc
{
    [[AFNetworkReachabilityManager sharedManager] stopMonitoring];
}

@end
